<?php

namespace backend\components\widget\adminLTE;

use Yii;
use yii\helpers\Html;

/**
 * Class ActionColumn
 * @package backend\components\widget
 */
class ActionColumn extends \yii\grid\ActionColumn
{
    public $header = '操作';
    /**
     * Initializes the default button rendering callback for single button.
     * @param string $name Button name as it's written in template
     * @param string $iconName The part of Bootstrap glyphicon class that makes it unique
     * @param array $additionalOptions Array of additional options
     * @since 2.0.11
     */
    protected function initDefaultButton($name, $iconName, $additionalOptions = [])
    {
        if (!isset($this->buttons[$name]) && strpos($this->template, '{' . $name . '}') !== false) {
            $this->buttons[$name] = function ($url, $model, $key) use ($name, $iconName, $additionalOptions) {
                switch ($name) {
                    case 'view':
                        $title = '查看';
                        $icon = Html::tag('i',' 查看',[
                            'class'=>'fa fa-eye'
                        ]);
                        $additionalOptions['class'] = 'btn btn-xs btn-primary';
                        break;
                    case 'update':
                        $title = '修改';
                        $icon = Html::tag('i',' 修改',[
                            'class'=>'fa fa-pencil'
                        ]);
                        $additionalOptions['class'] = 'btn btn-xs btn-warning';
                        break;
                    case 'delete':
                        $title = '删除';
                        $icon = Html::tag('i',' 删除',[
                            'class'=>'fa fa-trash-o'
                        ]);
                        $additionalOptions['class'] = 'btn btn-xs btn-danger';
                        break;
                    default:
                        $title = ucfirst($name);
                }
                $options = array_merge([
                    'title' => $title,
                    'aria-label' => $title,
                    'data-pjax' => '0',
                ], $additionalOptions, $this->buttonOptions);
                //$icon = Html::tag('span', '', ['class' => "glyphicon glyphicon-$iconName"]);
                return Html::a($icon, $url, $options);
            };
        }
    }
}